<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>转换字符的编码</title>
 </head>
 <body class="docs"><div id="layout">
  <div id="layout-content"><div id="function.mb-convert-encoding" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mb_convert_encoding</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7)</p><p class="refpurpose"><span class="refname">mb_convert_encoding</span> &mdash; <span class="dc-title">转换字符的编码</span></p>

 </div>
   
 <div class="refsect1 description" id="refsect1-function.mb-convert-encoding-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>mb_convert_encoding</strong></span>
    ( <span class="methodparam"><span class="type">string</span> <code class="parameter">$str</code></span>
   , <span class="methodparam"><span class="type">string</span> <code class="parameter">$to_encoding</code></span>
   [, <span class="methodparam"><span class="type"><a href="language.pseudo-types.html#language.types.mixed" class="type mixed">mixed</a></span> <code class="parameter">$from_encoding</code><span class="initializer"> = mb_internal_encoding()</span></span>
  ] ) : <span class="type">string</span></div>

  <p class="para rdfs-comment">
   将 <span class="type"><a href="language.types.string.html" class="type string">string</a></span> 类型 <code class="parameter">str</code> 的字符编码从可选的 <code class="parameter">from_encoding</code> 转换到 <code class="parameter">to_encoding</code>。
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.mb-convert-encoding-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<code class="parameter">str</code></dt>

     <dd>

      <p class="para">
       要编码的 <span class="type"><a href="language.types.string.html" class="type string">string</a></span>。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">to_encoding</code></dt>

     <dd>

      <p class="para">
       <code class="parameter">str</code> 要转换成的编码类型。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">from_encoding</code></dt>

     <dd>

      <p class="para">
       在转换前通过字符代码名称来指定。它可以是一个 <span class="type"><a href="language.types.array.html" class="type array">array</a></span> 也可以是逗号分隔的枚举列表。
       如果没有提供 <code class="parameter">from_encoding</code>，则会使用内部（internal）编码。
       
      </p>
      <p class="para">
      参见<a href="mbstring.supported_encodings.html" class="link">支持的编码</a>。
      </p>
     </dd>

    
   </dl>

  </p>
 </div>

 
 <div class="refsect1 returnvalues" id="refsect1-function.mb-convert-encoding-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   编码后的 <span class="type"><a href="language.types.string.html" class="type string">string</a></span>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.mb-convert-encoding-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-3174">
    <p><strong>Example #1 <span class="function"><strong>mb_convert_encoding()</strong></span> 例子</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">/*&nbsp;转换内部编码为&nbsp;SJIS&nbsp;*/<br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mb_convert_encoding</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"SJIS"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;将&nbsp;EUC-JP&nbsp;转换成&nbsp;UTF-7&nbsp;*/<br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mb_convert_encoding</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UTF-7"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EUC-JP"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;从&nbsp;JIS,&nbsp;eucjp-win,&nbsp;sjis-win&nbsp;中自动检测编码，并转换&nbsp;str&nbsp;到&nbsp;UCS-2LE&nbsp;*/<br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mb_convert_encoding</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"UCS-2LE"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"JIS,&nbsp;eucjp-win,&nbsp;sjis-win"</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">/*&nbsp;"auto"&nbsp;扩展成&nbsp;"ASCII,JIS,UTF-8,EUC-JP,SJIS"&nbsp;*/<br /></span><span style="color: #0000BB">$str&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mb_convert_encoding</span><span style="color: #007700">(</span><span style="color: #0000BB">$str</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"EUC-JP"</span><span style="color: #007700">,&nbsp;</span><span style="color: #DD0000">"auto"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</pre></div>
    </div>

   </div>
  </p>
 </div>

  
 <div class="refsect1 seealso" id="refsect1-function.mb-convert-encoding-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mb_detect_order.html" class="function" rel="rdfs-seeAlso">mb_detect_order()</a> - 设置/获取 字符编码的检测顺序</span></li>
   </ul>
  </p>
 </div>

 
</div></div></div></body></html>